home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / NSL 1.0 SDK / Headers & Source / NSLAPI.h next >
Encoding:
C/C++ Source or Header  |  1998-10-05  |  16.8 KB  |  422 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        NSLAPI.h
  3.  
  4.     Contains:    API for using the NSL Manager
  5.  
  6.     Written by:    Kevin Arnold & Dave Fisher
  7.  
  8.     Copyright:    © 1997 - 1998 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.     <43>    6/9/98         DMF        Moved non-public code and dec'ls to NSLTypedDataUtilities.c,h
  13.     <42>    5/3/98        DMF        Removed kNSLMismatchedBufferLengths enum element
  14.     <41>    5/3/98        DMF        Added kNSLNewDataEvent and kNSLContinueLookupEvent events
  15.     <40>    4/16/98        DMF        Updated the values of the error returns.  (in the comments)
  16.     <39>    4/10/98        KA        Added kNBPProtocolType
  17.     <38>    4/09/98        DMF        removed kNSLItemAlreadyInList enum
  18.     <37>    4/02/98        KA        readjusted the comments for the error nums
  19.     <36>    3/30/98        DMF        Added kNSLNullNeighborhoodPtr enum
  20.                                 Added kNSLSomePluginsFailedToLoad enum
  21.     <34>    3/26/98        KA        Removed outdated errors as well as protocol specific errors
  22.     <33>    3/25/98        DMF        Added kNSLBadDomainName enum value
  23.     <32>    3/23/98        DMF        Added kNSLNoPluginsForSearch enum value
  24.     <31>    3/18/98        KA        Changed kLastAndMeaningLessItemInEnum to kLastAndMeaningLessItemInNSLEnum
  25.     <30>    3/12/98        KA        Modified NSLParseRegistrationPB
  26.     <29>    3/9/98        DMF        Removed ClientAsyncInfo.totalItems and ClientAsyncInfo.alertThreshold
  27.                                 Changed PluginAsyncInfo.searchEvent to PluginAsyncInfo.searchDataType
  28.     <28>    3/9/98        KA        changed method to NSLMakeNewNeighborhood and added NSLFreeNeighborhood
  29.     <27>    3/6/98        KA        oops, forgot to get rid of the index...
  30.     <26>    3/6/98        KA        changed GetNth... to GetNext... iterators
  31.     <25>    3/6/98        KA        Took out references to protocolListOffset
  32.     <24>    3/6/98        KA&DMF    Made more cleanup and standardization of calls
  33.     <23>    3/6/98        KA        Created functions: GetNthNSLNeighborhood and GetNthNSLUrl
  34.     <22>    3/5/98        KA&DMF    Added concept of "NSLNeighborhood" which can denote a domain, zone, realm etc.
  35.     <22>    3/5/98        KA&DMF    Changed "Create" to "Make" in various calls
  36.     <21>    3/3/98        KA        Added kNSLPluginLoadFailed and kNSLNoPluginsFound errors
  37.     <20>    2/20/98        DMF        Added startTime and intStartTime to ClientAsyncInfo struct
  38.     <19>    2/20/98        DMF        Added kNSLMainThreadNotPausable error
  39.     <18>    2/12/98        DMF        Added asyncInfoPtr to NSLCreateRequest call
  40.                                 Removed kNSLSearchStateNotifyClient
  41.     <17>    2/11/98        DMF        Switched error returns to NSLError
  42.     <16>    2/5/98        DMF        Split AsyncInfo into PluginAsyncInfo and ClientAsyncInfo
  43.     <16>    2/5/98        DMF        Removed NSLGetNumResponders and NSLAddResultBuffer
  44.     <16>    2/5/98        DMF        Changed most API calls to return NSLError instead of OSStatus
  45.     <15>    2/4/98        DMF        Added asynchronous notification capability
  46.     <14>    2/3/98        DMF        Changed NSLErrNumToString to handle primary and secondary strings
  47.     <14>    2/3/98        DMF        Cleaned up commented out code etc.
  48.     <13>    2/2/98        DMF        Added NSLContinueLookup, mods to AsyncInfo
  49.     <0>        9/24/97        DMF        created (basing APIs on InternetServiceLocationAPI.h)
  50.         
  51.  
  52.     To Do:
  53. */
  54.  
  55.  
  56.  
  57. #ifndef __NSLAPI__
  58. #define __NSLAPI__
  59.  
  60. #pragma export on
  61.  
  62.  
  63. #define kMinNSLSystemVersion        (0x0800)                    // equiv. to 8.0
  64. #define    kMinNSLOTVersion            (0x0130)                    // equiv. to 1.3
  65. #define    kDefaultListSize            256                            // default list size for service and protocol lists
  66. #define    kURLDelimiter                ','                            // delimits URL's within memory buffers
  67. #define    kNSLNoContext                0                            // the default context for NSLError structs
  68. #define    kNSLErrorNoErr                {noErr, kNSLNoContext}
  69.  
  70. #if __cplusplus
  71. extern "C" {
  72. #endif
  73.  
  74. typedef struct NSLError
  75. {
  76.     OSStatus    theErr;
  77.     UInt32        theContext;
  78. } NSLError, *NSLErrorPtr;
  79.  
  80.  
  81. enum
  82. {
  83.     // Constants to use with NSLPrepareRequest
  84.     
  85. // this next one is not strictly an error.  The client is free to ignore this return, and nothing bad will happen
  86. // if it does.  It is informational only.
  87.     kDuplicateSearchInProgress                = 100,
  88.         
  89.     // Invalid enumeratorRef    
  90.     kNSLInvalidEnumeratorRef                = 0,        // this is not an error; it is the equiv to a NULL ptr
  91.         
  92.     // State codes for notifiers.
  93.     kNSLSearchStateBufferFull                = 1,
  94.     kNSLSearchStateOnGoing,
  95.     kNSLSearchStateComplete,
  96.     kNSLSearchStateStalled,
  97.     kNSLWaitingForContinue,
  98.  
  99.     // Event codes
  100.     kNSLServicesLookupDataEvent,
  101.     kNSLNeighborhoodLookupDataEvent,
  102.     kNSLNewDataEvent,
  103.     kNSLContinueLookupEvent,
  104.     
  105.     // Error codes
  106.     kNSLNavigationAPIErrorBase                    = -4200,
  107.     
  108. // UNABLE TO INITIALIZE THE MANAGER!!!!!  DO NOT CONTINUE!!!!
  109.     kNSLInitializationFailed                = kNSLNavigationAPIErrorBase,
  110.  
  111. // General NSL error codes.  If you change any of this part of the enum, please update the code values
  112. // given in the comments.  1/21/98 DMF
  113.     
  114.     kNSLNotInitialized,                                        // -4199
  115.     kNSLInsufficientSysVer,                                    // -4198
  116.     kNSLInsufficientOTVer,                                    // -4197
  117.     kNSLNoElementsInList,                                    // -4196
  118.     kNSLBadReferenceErr,                                    // -4195
  119.     kNSLBadServiceTypeErr,                                    // -4194
  120.     kNSLBadDataTypeErr,                                        // -4193
  121.     kNSLBadNetConnection,                                    // -4192
  122.     kNSLNoSupportForService,                                // -4191
  123.     kNSLInvalidPluginSpec,                                    // -4190
  124. //    kNSLMismatchedBufferLengths,                            // -4189
  125.     kNSLRequestBufferAlreadyInList,                            // -4189
  126.     kNSLNoContextAvailable,                                    // -4188    (ContinueLookup function ptr invalid)
  127.     kNSLBufferTooSmallForData,                                // -4187    (Client buffer too small for data from plugin)
  128.     kNSLCannotContinueLookup,                                // -4186    (Can't continue lookup; error or bad state)
  129.     kNSLBadClientInfoPtr,                                    // -4185    (nil ClientAsyncInfoPtr; no reference available)
  130.     kNSLNullListPtr,                                        // -4184    (client is trying to add items to a nil list)
  131.     kNSLBadProtocolTypeErr,                                    // -4183    (client is trying to add a null protocol type)
  132.     kNSLPluginLoadFailed,                                    // -4182    (manager unable to load one of the plugins)
  133.     kNSLNoPluginsFound,                                        // -4181    (manager didn't find any valid plugins to load)
  134.     kNSLSearchAlreadyInProgress,                            // -4180    (you can only have one ongoing search per clientRef)
  135.     kNSLNoPluginsForSearch,                                    // -4179    (no plugins will respond to search request; bad protocol(s)?)
  136.     kNSLNullNeighborhoodPtr,                                // -4178    (client passed a null neighborhood ptr)
  137.     kNSLSomePluginsFailedToLoad,                            // -4177    (one or more plugins failed to load, but at
  138.                                                             //            least one did load; this error isn't fatal)
  139.     
  140.     NSLErrNullPtrError,                                        // -4176
  141.     kNSLNotImplementedYet,                                    // -4175
  142.  
  143.     kLastAndMeaningLessItemInNSLEnum
  144. };
  145.  
  146. typedef    UInt32                NSLEventCode;
  147. typedef    UInt32                NSLRequestRef;
  148. typedef    UInt32                NSLDomainEnumeratorRef;
  149. typedef    UInt32                OneBasedIndex;
  150.  
  151. typedef UInt16                NSLPort;
  152. typedef char*                NSLPath;
  153. typedef char*                NSLServiceComments;
  154. typedef char*                NSLServiceType;
  155. typedef Handle                NSLServicesList;
  156. typedef char*                NSLAttribute;
  157. typedef unsigned char*        NSLNeighborhood;            // this is a pstring describing the textual Neighborhood name followed by a 
  158.                                                         // cstring which is a comma delimited list of protocols which can be used to
  159.                                                         // create a NSLProtocolList internally
  160.  
  161. typedef UInt32                NSLPluginSpec;
  162. typedef UInt32                NSLClientRef;
  163. typedef UInt16                NSLSearchState;                // longer lasting states of the search
  164. typedef UInt16                NSLDataType;
  165.  
  166. // the async information block for client<->manager interaction
  167. typedef struct ClientAsyncInfo
  168. {
  169.     void*            clientContextPtr;                    // set by the client for its own use
  170.     void*            mgrContextPtr;                        // set by NSL mgr; ptr to request object ptr
  171.     char*            resultBuffer;
  172.     long            bufferLen;
  173.     long            maxBufferSize;
  174.     UInt32            startTime;                            // when the search starts, to use with maxSearchTime to determine time-out condition
  175.     UInt32            intStartTime;                        // used with alertInterval
  176.     UInt32            maxSearchTime;                        // total time for search, in ticks (0 == no time limit)
  177.     UInt32            alertInterval;                        // call client's notifier or return, every this many ticks ( 0 == don't use this param)
  178.     UInt32            totalItems;                            // total number of tuples currently in buffer
  179.     UInt32            alertThreshold;                        // call client's notifier or return, every this many items found ( 0 == don't use this param)
  180.     NSLSearchState    searchState;
  181.     NSLError        searchResult;
  182.     UInt32            searchDataType;                        // this is a data type code which allows the client's asyncNotifier to properly
  183. } ClientAsyncInfo, *ClientAsyncInfoPtr;                    // handle the data in resultBuffer.
  184.  
  185.  
  186. // the async information block plugin<->manager interaction
  187. typedef struct PluginAsyncInfo
  188. {
  189.     void*            mgrContextPtr;                        // set by NSL mgr; ptr to request object ptr
  190.     void*            pluginContextPtr;                    // set/used by individual plugins
  191.     void*            pluginPtr;                            // ptr to the plugin object waiting for continue lookup call
  192.     char*            resultBuffer;                        // set by plugin to point at data
  193.     long            bufferLen;
  194.     long            maxBufferSize;
  195.     UInt32            maxSearchTime;                        // total time for search, in ticks (0 == no time limit)
  196.     UInt32            reserved1;                    
  197.     UInt32            reserved2;                        
  198.     UInt32            reserved3;                    
  199.     NSLClientRef    clientRef;
  200.     NSLRequestRef    requestRef;
  201.     NSLSearchState    searchState;
  202.     OSStatus        searchResult;
  203. } PluginAsyncInfo, *PluginAsyncInfoPtr;
  204.  
  205.  
  206. // the mgr asynchronous notifier routine.
  207. typedef pascal void        (*NSLMgrNotifyProcPtr)(void* thePluginAsyncInfo);
  208.  
  209. // the client asynchronous notifier routine.
  210. typedef pascal void        (*NSLClientNotifyProcPtr)(void* theClientAsyncInfo);
  211.  
  212. // the NSLContinueLookup routine that is stored in mgrContextPtr
  213. typedef pascal NSLError        (*NSLContinueLookupPtr)(PluginAsyncInfoPtr theAsyncInfo);
  214.  
  215.  
  216. // this struct is a format for dealing with our internal data representation.  Typed data will be contiguous chunk of
  217. // memory, with the first 4 bytes being a data "descriptor".
  218. typedef struct TypedData {
  219.     unsigned long            dataType;
  220.     unsigned long            lengthOfData;
  221. //    void*                        theData;
  222. } TypedData, *TypedDataPtr;
  223.  
  224. #define kNSLDataType        'NSL_'
  225.  
  226. // This is just a header at the beginning of a handle that stores our list of service types.
  227. // Each service type is a pascal string, so each service type starts after the end of the
  228. // previous one.
  229. typedef struct NSLServicesListHeader {
  230.     unsigned long    numServices;
  231.     unsigned long    logicalLen;                        // length of all usable data in handle
  232. //    Ptr                firstService;
  233. } NSLServicesListHeader, *NSLServicesListHeaderPtr;
  234.  
  235.  
  236. // some defs for common protocols
  237. #define    kSLPProtocolType            "SLP"
  238. #define    kDNSProtocolType            "DNS"
  239. #define    kLDAPProtocolType            "LDAP"
  240. #define kNBPProtocolType            "NBP"
  241.  
  242. // general information from a plug-in.  Includes supported protocols, data types and services,
  243. // as well as an info/comment string describing the function of the plug-in in human-readable
  244. // form.  The offsets point to the beginning of each list of data returned, and the protocol
  245. // data offset is the startOfData member of the struct
  246. typedef struct PluginData {
  247.     long        reserved1;
  248.     long        reserved2;
  249.     long        reserved3;
  250.     Boolean        isPurgeable;
  251.     UInt16        totalLen;                        // length of everything, including header
  252.     UInt16        dataTypeOffset;
  253.     UInt16        serviceListOffset;
  254.     UInt16        protocolListOffset;
  255.     UInt16        commentStringOffset;
  256. //    char*        startOfData;                    // protocol data is first on the list
  257. } PluginData, *PluginDataPtr;
  258.  
  259.  
  260. #define kNSLDataTypeNSL        'NSL_'
  261.  
  262. //-----------------------------------------------------------------------------
  263. //    Basic API Utility calls: sufficient to create, and parse data structures
  264. //-----------------------------------------------------------------------------
  265.  
  266. pascal NSLServicesList    NSLMakeNewServicesList( char* initialServiceList );
  267. pascal NSLError            NSLAddServiceToServicesList( NSLServicesList serviceList, NSLServiceType serviceType );
  268. pascal void                NSLDisposeServicesList( NSLServicesList theList );
  269.  
  270. pascal NSLNeighborhood    NSLMakeNewNeighborhood( char* name, char* protocolList );    // the name reflects the name of the Neighborhood
  271.                                                                                     // i.e. "apple.com." or "DA3 4th - North"
  272.                                                                                     // the protocolList is a comma delimited list of 
  273.                                                                                     // protocols that the Neighborhood might exist in.
  274.                                                                                     // If the user passes in NULL, then all protocols will
  275.                                                                                     // be queried.  Result must be disposed of by user by
  276.                                                                                     // calling NSLFreeNeighborhood.
  277. pascal NSLNeighborhood    NSLFreeNeighborhood( NSLNeighborhood neighborhood );                                                                                    
  278.  
  279. pascal void NSLGetNameFromNeighborhood( NSLNeighborhood neighborhood, char** name, long* length );
  280.  
  281. // create a block of formatted data, pointed to by newDataPtr.  This will be used
  282. // in calls (typically request-related calls) for plug-ins that handle the NSL data type.
  283. pascal OSStatus NSLMakeRequestPB(    NSLServicesList serviceList,
  284.                                     NSLAttribute attribute,
  285.                                     TypedDataPtr* newDataPtr );
  286.                                 
  287. // provides the inverse of NSLMakeRequestPB, filling out the offsets found within newDataPtr
  288. pascal OSStatus NSLParseRequestPB(    TypedDataPtr newDataPtr, 
  289.                                     UInt16* serviceListOffset,
  290.                                     UInt16* attributeOffset );
  291.  
  292. // same idea as above, used to register a service with a NSL-aware plug-in(s)
  293. pascal OSStatus NSLMakeRegistrationPB(    NSLAttribute attribute,
  294.                                         NSLPath urlToService,
  295.                                         TypedDataPtr* newDataPtr );
  296.     
  297. // used by plugins to parse a registrationPB
  298. pascal OSStatus NSLParseRegistrationPB(    TypedDataPtr newDataPtr, 
  299.                                         char**    attributePtr,
  300.                                         UInt16*    attributeLen,
  301.                                         char**    urlPtr,
  302.                                         UInt16* urlLen );
  303.  
  304. // releases any storage created with MakeXXXPB calls, associated with TypedData.
  305. pascal TypedDataPtr NSLFreeTypedDataPtr( TypedDataPtr nslTypeData );
  306.  
  307. // utility function that returns whether a url was found, a pointer to the beginning
  308. // of the url, and the length of the URL.
  309. pascal Boolean NSLGetNextUrl( ClientAsyncInfoPtr infoPtr, char** urlPtr, long* urlLength );
  310.  
  311. // utility function that returns whether a Neighborhood was found, a pointer to the beginning
  312. // of the Neighborhood, and the length of the Neighborhood.
  313. pascal Boolean NSLGetNextNeighborhood( ClientAsyncInfoPtr infoPtr, NSLNeighborhood* neighborhood, long* neighborhoodLength );
  314.  
  315.  
  316. //
  317. // NSLErrNumToString:    convert a numeric error code to its string equivalent.  Caller must
  318. //                         have allocated sufficient space to store both strings.  (Max 255 chars each)
  319. //                                
  320. //                        The errorString parameter will return a textual explanation of what is wrong,
  321. //                        while the solutionString returns a possible solution to get around the problem
  322. //
  323.  
  324. pascal OSStatus    NSLErrorToString(NSLError theErr, char* errorString, char* solutionString);
  325.  
  326.  
  327. //-----------------------------------------------------------------------------
  328. //    Basic API calls: sufficient to create simple requests, and receive answers
  329. //-----------------------------------------------------------------------------
  330.  
  331. pascal OSStatus    NSLOpenNavigationAPI( NSLClientRef* newRef );
  332. pascal void        NSLCloseNavigationAPI( NSLClientRef theClient );
  333.  
  334. //
  335. //    NSLPrepareRequest:    creates an NSLRequestRef, sets up some internal data
  336. //
  337. //    notifier is an NSLNotifyProcPtr that will be called when data is available, when the lookup has completed, or if an error occurs.
  338. //    when the notifier is called, the cookie will be the NSLRequestRef.  If notifier is NULL, then
  339. // the NSLManager will assume that the request is made synchronously.  This should only be used
  340. // while in a separate thread, so that the client app can still process events, etc.
  341. //    
  342. //    contextPtr is a void* which is passed as the contextPtr argument when the notifier is called.  
  343. //    
  344. //    upon exit:
  345. //    1) ref will contain a pointer to a NSLRequestRef which must be passed to all other functions
  346. //    which require a NSLRequestRef.
  347. //
  348. //    2) infoPtr will point to a newly created ClientAsycnInfoPtr which will be disposed by the manager when the search is completed
  349. //
  350. //    NOTE: Only one search can be running at a time per clientRef.
  351.  
  352. pascal NSLError NSLPrepareRequest(    NSLClientNotifyProcPtr    notifier,
  353.                                     void*                    contextPtr,
  354.                                     NSLClientRef            theClient,
  355.                                     NSLRequestRef*            ref,
  356.                                     char*                    bufPtr,
  357.                                     unsigned long            bufLen,
  358.                                     ClientAsyncInfoPtr*        infoPtr);
  359.  
  360.  
  361. //
  362. // NSLStartNeighborhoodLookup: looking for neighborhoods associated with or neighboring a particular neighborhood
  363. //
  364. //    Passing in NULL for neighborhood will generate a list of a default neighborhood(s)
  365. // 
  366.  
  367. pascal NSLError NSLStartNeighborhoodLookup( NSLRequestRef ref,
  368.                                             NSLNeighborhood neighborhood, 
  369.                                             ClientAsyncInfo* asyncInfo );
  370.  
  371. //
  372. // NSLStartServicesLookup: starts looking for entities if the specified type in the specified neighborhood
  373. // 
  374.  
  375. pascal NSLError    NSLStartServicesLookup(    NSLRequestRef ref, 
  376.                                         NSLNeighborhood neighborhood, 
  377.                                         TypedDataPtr requestData, 
  378.                                         ClientAsyncInfo* asyncInfo );
  379.  
  380.  
  381. //
  382. // NSLContinueLookup:  continues a paused/outstanding lookup
  383. //
  384.  
  385. pascal NSLError    NSLContinueLookup( ClientAsyncInfo* asyncInfo );
  386.  
  387.  
  388. //
  389. // NSLCancelRequest: cancels an ongoing search
  390. //
  391.  
  392. pascal NSLError    NSLCancelRequest( NSLRequestRef ref );
  393.  
  394. //
  395. // NSLDeleteRequest: deletes info associated with this ref.  The ClientAsyncInfoPtr will no longer be valid
  396. //    This must be called when the client is no longer using this requestRef.
  397. //
  398.  
  399. pascal NSLError    NSLDeleteRequest( NSLRequestRef ref );
  400.  
  401. //
  402. // NSLRegisterService: registers a service type
  403. //
  404.  
  405. pascal NSLError NSLRegisterService( TypedDataPtr requestData );
  406.  
  407. //
  408. // NSLDeRegisterService: unregisters a service
  409. //
  410.  
  411. pascal NSLError NSLDeregisterService( TypedDataPtr requestData );
  412.  
  413.  
  414.  
  415. #if __cplusplus
  416. }
  417. #endif
  418.  
  419. #pragma export off
  420.  
  421.  
  422. #endif